<?php
	require_once ("View/LoginView.php");
	require_once ("View/RegisterView.php");
	require_once ("View/NavigationView.php");
	require_once ("View/ForumView.php");
    require_once ("LoginController.php");
	require_once ("RegisterController.php");
	require_once ("ForumController.php");
	require_once ("Model/LoginHandler.php");
	require_once ("Model/UserHandler.php");
	require_once ("Model/ForumHandler.php");
	require_once ("Model/Post.php");
	require_once ("Model/Topic.php");
	require_once ("Model/Category.php");
	require_once ("Model/Privmess.php");
	require_once ("../Validation/Validate.php");
	require_once ("../Log/Log.php");
	require_once ("../Log/LogView.php");
    	
    Class MasterController{
    	
		public function DoControll($aDBConnection){

			$aUserHandler = new UserHandler($aDBConnection);
			$aLoginHandler = new LoginHandler($aUserHandler);
			$aForumHandler = new ForumHandler($aDBConnection);
			
			$aNavigationView = new NavigationView();
			$aLoginView = new LoginView();
			$aRegisterView = new RegisterView();
			$aForumView = new ForumView($aNavigationView, $aForumHandler);
			
			$aLoginController = new LoginController();
			$aRegisterController = new RegisterController();
						
			$header = $aForumView->DrawForumHeader();
			$output = null;
			$bottomoutput = null;
			
			if($aNavigationView->IsRegisterControllerActive() == true){
				$output .= $aRegisterController->DoControll($aRegisterView,$aUserHandler);
				$output .= $aNavigationView->DoBackToLoginLink() . $aForumView->AddEndDiv();
			}
			else{
				$output .= $aLoginController->DoControll($aLoginView, $aLoginHandler);
				$output = $aForumView->DrawNewLoginHeader($aLoginHandler->IsLoggedIn()) . $output;
				
				if ($aLoginHandler->IsLoggedIn() == false){
					$output .= $aNavigationView->DoRegisterLink();
				}else {
					$aForumController = new ForumController($aForumView, $aForumHandler, $aNavigationView, $aLoginHandler->GetCurrentUser());
					$bottomoutput = $output;
					$output = null;
					$output .= $aForumController->DoControll();
				}
			}
			
			return $header . $output . $bottomoutput;
		}
    }